siu.h 5.6 KB

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