siu.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // siu.h - ALSA SoC driver for Renesas SH7343, SH7722 SIU peripheral.
  4. //
  5. // Copyright (C) 2009-2010 Guennadi Liakhovetski <[email protected]>
  6. // Copyright (C) 2006 Carlos Munoz <[email protected]>
  7. #ifndef SIU_H
  8. #define SIU_H
  9. /* Common kernel and user-space firmware-building defines and types */
  10. #define YRAM0_SIZE (0x0040 / 4) /* 16 */
  11. #define YRAM1_SIZE (0x0080 / 4) /* 32 */
  12. #define YRAM2_SIZE (0x0040 / 4) /* 16 */
  13. #define YRAM3_SIZE (0x0080 / 4) /* 32 */
  14. #define YRAM4_SIZE (0x0080 / 4) /* 32 */
  15. #define YRAM_DEF_SIZE (YRAM0_SIZE + YRAM1_SIZE + YRAM2_SIZE + \
  16. YRAM3_SIZE + YRAM4_SIZE)
  17. #define YRAM_FIR_SIZE (0x0400 / 4) /* 256 */
  18. #define YRAM_IIR_SIZE (0x0200 / 4) /* 128 */
  19. #define XRAM0_SIZE (0x0400 / 4) /* 256 */
  20. #define XRAM1_SIZE (0x0200 / 4) /* 128 */
  21. #define XRAM2_SIZE (0x0200 / 4) /* 128 */
  22. /* PRAM program array size */
  23. #define PRAM0_SIZE (0x0100 / 4) /* 64 */
  24. #define PRAM1_SIZE ((0x2000 - 0x0100) / 4) /* 1984 */
  25. #include <linux/types.h>
  26. struct siu_spb_param {
  27. __u32 ab1a; /* input FIFO address */
  28. __u32 ab0a; /* output FIFO address */
  29. __u32 dir; /* 0=the ather except CPUOUTPUT, 1=CPUINPUT */
  30. __u32 event; /* SPB program starting conditions */
  31. __u32 stfifo; /* STFIFO register setting value */
  32. __u32 trdat; /* TRDAT register setting value */
  33. };
  34. struct siu_firmware {
  35. __u32 yram_fir_coeff[YRAM_FIR_SIZE];
  36. __u32 pram0[PRAM0_SIZE];
  37. __u32 pram1[PRAM1_SIZE];
  38. __u32 yram0[YRAM0_SIZE];
  39. __u32 yram1[YRAM1_SIZE];
  40. __u32 yram2[YRAM2_SIZE];
  41. __u32 yram3[YRAM3_SIZE];
  42. __u32 yram4[YRAM4_SIZE];
  43. __u32 spbpar_num;
  44. struct siu_spb_param spbpar[32];
  45. };
  46. #ifdef __KERNEL__
  47. #include <linux/dmaengine.h>
  48. #include <linux/interrupt.h>
  49. #include <linux/io.h>
  50. #include <linux/sh_dma.h>
  51. #include <sound/core.h>
  52. #include <sound/pcm.h>
  53. #include <sound/soc.h>
  54. #define SIU_PERIOD_BYTES_MAX 8192 /* DMA transfer/period size */
  55. #define SIU_PERIOD_BYTES_MIN 256 /* DMA transfer/period size */
  56. #define SIU_PERIODS_MAX 64 /* Max periods in buffer */
  57. #define SIU_PERIODS_MIN 4 /* Min periods in buffer */
  58. #define SIU_BUFFER_BYTES_MAX (SIU_PERIOD_BYTES_MAX * SIU_PERIODS_MAX)
  59. /* SIU ports: only one can be used at a time */
  60. enum {
  61. SIU_PORT_A,
  62. SIU_PORT_B,
  63. SIU_PORT_NUM,
  64. };
  65. /* SIU clock configuration */
  66. enum {
  67. SIU_CLKA_PLL,
  68. SIU_CLKA_EXT,
  69. SIU_CLKB_PLL,
  70. SIU_CLKB_EXT
  71. };
  72. struct device;
  73. struct siu_info {
  74. struct device *dev;
  75. int port_id;
  76. u32 __iomem *pram;
  77. u32 __iomem *xram;
  78. u32 __iomem *yram;
  79. u32 __iomem *reg;
  80. struct siu_firmware fw;
  81. };
  82. struct siu_stream {
  83. struct work_struct work;
  84. struct snd_pcm_substream *substream;
  85. snd_pcm_format_t format;
  86. size_t buf_bytes;
  87. size_t period_bytes;
  88. int cur_period; /* Period currently in dma */
  89. u32 volume;
  90. snd_pcm_sframes_t xfer_cnt; /* Number of frames */
  91. u8 rw_flg; /* transfer status */
  92. /* DMA status */
  93. struct dma_chan *chan; /* DMA channel */
  94. struct dma_async_tx_descriptor *tx_desc;
  95. dma_cookie_t cookie;
  96. struct sh_dmae_slave param;
  97. };
  98. struct siu_port {
  99. unsigned long play_cap; /* Used to track full duplex */
  100. struct snd_pcm *pcm;
  101. struct siu_stream playback;
  102. struct siu_stream capture;
  103. u32 stfifo; /* STFIFO value from firmware */
  104. u32 trdat; /* TRDAT value from firmware */
  105. };
  106. extern struct siu_port *siu_ports[SIU_PORT_NUM];
  107. static inline struct siu_port *siu_port_info(struct snd_pcm_substream *substream)
  108. {
  109. struct platform_device *pdev =
  110. to_platform_device(substream->pcm->card->dev);
  111. return siu_ports[pdev->id];
  112. }
  113. /* Register access */
  114. static inline void siu_write32(u32 __iomem *addr, u32 val)
  115. {
  116. __raw_writel(val, addr);
  117. }
  118. static inline u32 siu_read32(u32 __iomem *addr)
  119. {
  120. return __raw_readl(addr);
  121. }
  122. /* SIU registers */
  123. #define SIU_IFCTL (0x000 / sizeof(u32))
  124. #define SIU_SRCTL (0x004 / sizeof(u32))
  125. #define SIU_SFORM (0x008 / sizeof(u32))
  126. #define SIU_CKCTL (0x00c / sizeof(u32))
  127. #define SIU_TRDAT (0x010 / sizeof(u32))
  128. #define SIU_STFIFO (0x014 / sizeof(u32))
  129. #define SIU_DPAK (0x01c / sizeof(u32))
  130. #define SIU_CKREV (0x020 / sizeof(u32))
  131. #define SIU_EVNTC (0x028 / sizeof(u32))
  132. #define SIU_SBCTL (0x040 / sizeof(u32))
  133. #define SIU_SBPSET (0x044 / sizeof(u32))
  134. #define SIU_SBFSTS (0x068 / sizeof(u32))
  135. #define SIU_SBDVCA (0x06c / sizeof(u32))
  136. #define SIU_SBDVCB (0x070 / sizeof(u32))
  137. #define SIU_SBACTIV (0x074 / sizeof(u32))
  138. #define SIU_DMAIA (0x090 / sizeof(u32))
  139. #define SIU_DMAIB (0x094 / sizeof(u32))
  140. #define SIU_DMAOA (0x098 / sizeof(u32))
  141. #define SIU_DMAOB (0x09c / sizeof(u32))
  142. #define SIU_DMAML (0x0a0 / sizeof(u32))
  143. #define SIU_SPSTS (0x0cc / sizeof(u32))
  144. #define SIU_SPCTL (0x0d0 / sizeof(u32))
  145. #define SIU_BRGASEL (0x100 / sizeof(u32))
  146. #define SIU_BRRA (0x104 / sizeof(u32))
  147. #define SIU_BRGBSEL (0x108 / sizeof(u32))
  148. #define SIU_BRRB (0x10c / sizeof(u32))
  149. extern const struct snd_soc_component_driver siu_component;
  150. extern struct siu_info *siu_i2s_data;
  151. int siu_init_port(int port, struct siu_port **port_info, struct snd_card *card);
  152. void siu_free_port(struct siu_port *port_info);
  153. #endif
  154. #endif /* SIU_H */