mcbsp.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*
  2. * sound/soc/omap/mcbsp.h
  3. *
  4. * OMAP Multi-Channel Buffered Serial Port
  5. *
  6. * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
  7. * Peter Ujfalusi <peter.ujfalusi@ti.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. */
  24. #ifndef __ASOC_MCBSP_H
  25. #define __ASOC_MCBSP_H
  26. #ifdef CONFIG_ARCH_OMAP1
  27. #define mcbsp_omap1() 1
  28. #else
  29. #define mcbsp_omap1() 0
  30. #endif
  31. #include <sound/dmaengine_pcm.h>
  32. /* McBSP register numbers. Register address offset = num * reg_step */
  33. enum {
  34. /* Common registers */
  35. OMAP_MCBSP_REG_SPCR2 = 4,
  36. OMAP_MCBSP_REG_SPCR1,
  37. OMAP_MCBSP_REG_RCR2,
  38. OMAP_MCBSP_REG_RCR1,
  39. OMAP_MCBSP_REG_XCR2,
  40. OMAP_MCBSP_REG_XCR1,
  41. OMAP_MCBSP_REG_SRGR2,
  42. OMAP_MCBSP_REG_SRGR1,
  43. OMAP_MCBSP_REG_MCR2,
  44. OMAP_MCBSP_REG_MCR1,
  45. OMAP_MCBSP_REG_RCERA,
  46. OMAP_MCBSP_REG_RCERB,
  47. OMAP_MCBSP_REG_XCERA,
  48. OMAP_MCBSP_REG_XCERB,
  49. OMAP_MCBSP_REG_PCR0,
  50. OMAP_MCBSP_REG_RCERC,
  51. OMAP_MCBSP_REG_RCERD,
  52. OMAP_MCBSP_REG_XCERC,
  53. OMAP_MCBSP_REG_XCERD,
  54. OMAP_MCBSP_REG_RCERE,
  55. OMAP_MCBSP_REG_RCERF,
  56. OMAP_MCBSP_REG_XCERE,
  57. OMAP_MCBSP_REG_XCERF,
  58. OMAP_MCBSP_REG_RCERG,
  59. OMAP_MCBSP_REG_RCERH,
  60. OMAP_MCBSP_REG_XCERG,
  61. OMAP_MCBSP_REG_XCERH,
  62. /* OMAP1-OMAP2420 registers */
  63. OMAP_MCBSP_REG_DRR2 = 0,
  64. OMAP_MCBSP_REG_DRR1,
  65. OMAP_MCBSP_REG_DXR2,
  66. OMAP_MCBSP_REG_DXR1,
  67. /* OMAP2430 and onwards */
  68. OMAP_MCBSP_REG_DRR = 0,
  69. OMAP_MCBSP_REG_DXR = 2,
  70. OMAP_MCBSP_REG_SYSCON = 35,
  71. OMAP_MCBSP_REG_THRSH2,
  72. OMAP_MCBSP_REG_THRSH1,
  73. OMAP_MCBSP_REG_IRQST = 40,
  74. OMAP_MCBSP_REG_IRQEN,
  75. OMAP_MCBSP_REG_WAKEUPEN,
  76. OMAP_MCBSP_REG_XCCR,
  77. OMAP_MCBSP_REG_RCCR,
  78. OMAP_MCBSP_REG_XBUFFSTAT,
  79. OMAP_MCBSP_REG_RBUFFSTAT,
  80. OMAP_MCBSP_REG_SSELCR,
  81. };
  82. /* OMAP3 sidetone control registers */
  83. #define OMAP_ST_REG_REV 0x00
  84. #define OMAP_ST_REG_SYSCONFIG 0x10
  85. #define OMAP_ST_REG_IRQSTATUS 0x18
  86. #define OMAP_ST_REG_IRQENABLE 0x1C
  87. #define OMAP_ST_REG_SGAINCR 0x24
  88. #define OMAP_ST_REG_SFIRCR 0x28
  89. #define OMAP_ST_REG_SSELCR 0x2C
  90. /************************** McBSP SPCR1 bit definitions ***********************/
  91. #define RRST BIT(0)
  92. #define RRDY BIT(1)
  93. #define RFULL BIT(2)
  94. #define RSYNC_ERR BIT(3)
  95. #define RINTM(value) (((value) & 0x3) << 4) /* bits 4:5 */
  96. #define ABIS BIT(6)
  97. #define DXENA BIT(7)
  98. #define CLKSTP(value) (((value) & 0x3) << 11) /* bits 11:12 */
  99. #define RJUST(value) (((value) & 0x3) << 13) /* bits 13:14 */
  100. #define ALB BIT(15)
  101. #define DLB BIT(15)
  102. /************************** McBSP SPCR2 bit definitions ***********************/
  103. #define XRST BIT(0)
  104. #define XRDY BIT(1)
  105. #define XEMPTY BIT(2)
  106. #define XSYNC_ERR BIT(3)
  107. #define XINTM(value) (((value) & 0x3) << 4) /* bits 4:5 */
  108. #define GRST BIT(6)
  109. #define FRST BIT(7)
  110. #define SOFT BIT(8)
  111. #define FREE BIT(9)
  112. /************************** McBSP PCR bit definitions *************************/
  113. #define CLKRP BIT(0)
  114. #define CLKXP BIT(1)
  115. #define FSRP BIT(2)
  116. #define FSXP BIT(3)
  117. #define DR_STAT BIT(4)
  118. #define DX_STAT BIT(5)
  119. #define CLKS_STAT BIT(6)
  120. #define SCLKME BIT(7)
  121. #define CLKRM BIT(8)
  122. #define CLKXM BIT(9)
  123. #define FSRM BIT(10)
  124. #define FSXM BIT(11)
  125. #define RIOEN BIT(12)
  126. #define XIOEN BIT(13)
  127. #define IDLE_EN BIT(14)
  128. /************************** McBSP RCR1 bit definitions ************************/
  129. #define RWDLEN1(value) (((value) & 0x7) << 5) /* Bits 5:7 */
  130. #define RFRLEN1(value) (((value) & 0x7f) << 8) /* Bits 8:14 */
  131. /************************** McBSP XCR1 bit definitions ************************/
  132. #define XWDLEN1(value) (((value) & 0x7) << 5) /* Bits 5:7 */
  133. #define XFRLEN1(value) (((value) & 0x7f) << 8) /* Bits 8:14 */
  134. /*************************** McBSP RCR2 bit definitions ***********************/
  135. #define RDATDLY(value) ((value) & 0x3) /* Bits 0:1 */
  136. #define RFIG BIT(2)
  137. #define RCOMPAND(value) (((value) & 0x3) << 3) /* Bits 3:4 */
  138. #define RWDLEN2(value) (((value) & 0x7) << 5) /* Bits 5:7 */
  139. #define RFRLEN2(value) (((value) & 0x7f) << 8) /* Bits 8:14 */
  140. #define RPHASE BIT(15)
  141. /*************************** McBSP XCR2 bit definitions ***********************/
  142. #define XDATDLY(value) ((value) & 0x3) /* Bits 0:1 */
  143. #define XFIG BIT(2)
  144. #define XCOMPAND(value) (((value) & 0x3) << 3) /* Bits 3:4 */
  145. #define XWDLEN2(value) (((value) & 0x7) << 5) /* Bits 5:7 */
  146. #define XFRLEN2(value) (((value) & 0x7f) << 8) /* Bits 8:14 */
  147. #define XPHASE BIT(15)
  148. /************************* McBSP SRGR1 bit definitions ************************/
  149. #define CLKGDV(value) ((value) & 0x7f) /* Bits 0:7 */
  150. #define FWID(value) (((value) & 0xff) << 8) /* Bits 8:15 */
  151. /************************* McBSP SRGR2 bit definitions ************************/
  152. #define FPER(value) ((value) & 0x0fff) /* Bits 0:11 */
  153. #define FSGM BIT(12)
  154. #define CLKSM BIT(13)
  155. #define CLKSP BIT(14)
  156. #define GSYNC BIT(15)
  157. /************************* McBSP MCR1 bit definitions *************************/
  158. #define RMCM BIT(0)
  159. #define RCBLK(value) (((value) & 0x7) << 2) /* Bits 2:4 */
  160. #define RPABLK(value) (((value) & 0x3) << 5) /* Bits 5:6 */
  161. #define RPBBLK(value) (((value) & 0x3) << 7) /* Bits 7:8 */
  162. /************************* McBSP MCR2 bit definitions *************************/
  163. #define XMCM(value) ((value) & 0x3) /* Bits 0:1 */
  164. #define XCBLK(value) (((value) & 0x7) << 2) /* Bits 2:4 */
  165. #define XPABLK(value) (((value) & 0x3) << 5) /* Bits 5:6 */
  166. #define XPBBLK(value) (((value) & 0x3) << 7) /* Bits 7:8 */
  167. /*********************** McBSP XCCR bit definitions *************************/
  168. #define XDISABLE BIT(0)
  169. #define XDMAEN BIT(3)
  170. #define DILB BIT(5)
  171. #define XFULL_CYCLE BIT(11)
  172. #define DXENDLY(value) (((value) & 0x3) << 12) /* Bits 12:13 */
  173. #define PPCONNECT BIT(14)
  174. #define EXTCLKGATE BIT(15)
  175. /********************** McBSP RCCR bit definitions *************************/
  176. #define RDISABLE BIT(0)
  177. #define RDMAEN BIT(3)
  178. #define RFULL_CYCLE BIT(11)
  179. /********************** McBSP SYSCONFIG bit definitions ********************/
  180. #define SOFTRST BIT(1)
  181. #define ENAWAKEUP BIT(2)
  182. #define SIDLEMODE(value) (((value) & 0x3) << 3)
  183. #define CLOCKACTIVITY(value) (((value) & 0x3) << 8)
  184. /********************** McBSP SSELCR bit definitions ***********************/
  185. #define SIDETONEEN BIT(10)
  186. /********************** McBSP Sidetone SYSCONFIG bit definitions ***********/
  187. #define ST_AUTOIDLE BIT(0)
  188. /********************** McBSP Sidetone SGAINCR bit definitions *************/
  189. #define ST_CH0GAIN(value) ((value) & 0xffff) /* Bits 0:15 */
  190. #define ST_CH1GAIN(value) (((value) & 0xffff) << 16) /* Bits 16:31 */
  191. /********************** McBSP Sidetone SFIRCR bit definitions **************/
  192. #define ST_FIRCOEFF(value) ((value) & 0xffff) /* Bits 0:15 */
  193. /********************** McBSP Sidetone SSELCR bit definitions **************/
  194. #define ST_SIDETONEEN BIT(0)
  195. #define ST_COEFFWREN BIT(1)
  196. #define ST_COEFFWRDONE BIT(2)
  197. /********************** McBSP DMA operating modes **************************/
  198. #define MCBSP_DMA_MODE_ELEMENT 0
  199. #define MCBSP_DMA_MODE_THRESHOLD 1
  200. /********************** McBSP WAKEUPEN/IRQST/IRQEN bit definitions *********/
  201. #define RSYNCERREN BIT(0)
  202. #define RFSREN BIT(1)
  203. #define REOFEN BIT(2)
  204. #define RRDYEN BIT(3)
  205. #define RUNDFLEN BIT(4)
  206. #define ROVFLEN BIT(5)
  207. #define XSYNCERREN BIT(7)
  208. #define XFSXEN BIT(8)
  209. #define XEOFEN BIT(9)
  210. #define XRDYEN BIT(10)
  211. #define XUNDFLEN BIT(11)
  212. #define XOVFLEN BIT(12)
  213. #define XEMPTYEOFEN BIT(14)
  214. /* Clock signal muxing options */
  215. #define CLKR_SRC_CLKR 0 /* CLKR signal is from the CLKR pin */
  216. #define CLKR_SRC_CLKX 1 /* CLKR signal is from the CLKX pin */
  217. #define FSR_SRC_FSR 2 /* FSR signal is from the FSR pin */
  218. #define FSR_SRC_FSX 3 /* FSR signal is from the FSX pin */
  219. /* McBSP functional clock sources */
  220. #define MCBSP_CLKS_PRCM_SRC 0
  221. #define MCBSP_CLKS_PAD_SRC 1
  222. /* we don't do multichannel for now */
  223. struct omap_mcbsp_reg_cfg {
  224. u16 spcr2;
  225. u16 spcr1;
  226. u16 rcr2;
  227. u16 rcr1;
  228. u16 xcr2;
  229. u16 xcr1;
  230. u16 srgr2;
  231. u16 srgr1;
  232. u16 mcr2;
  233. u16 mcr1;
  234. u16 pcr0;
  235. u16 rcerc;
  236. u16 rcerd;
  237. u16 xcerc;
  238. u16 xcerd;
  239. u16 rcere;
  240. u16 rcerf;
  241. u16 xcere;
  242. u16 xcerf;
  243. u16 rcerg;
  244. u16 rcerh;
  245. u16 xcerg;
  246. u16 xcerh;
  247. u16 xccr;
  248. u16 rccr;
  249. };
  250. struct omap_mcbsp_st_data {
  251. void __iomem *io_base_st;
  252. bool running;
  253. bool enabled;
  254. s16 taps[128]; /* Sidetone filter coefficients */
  255. int nr_taps; /* Number of filter coefficients in use */
  256. s16 ch0gain;
  257. s16 ch1gain;
  258. };
  259. struct omap_mcbsp {
  260. struct device *dev;
  261. struct clk *fclk;
  262. spinlock_t lock;
  263. unsigned long phys_base;
  264. unsigned long phys_dma_base;
  265. void __iomem *io_base;
  266. u8 id;
  267. /*
  268. * Flags indicating is the bus already activated and configured by
  269. * another substream
  270. */
  271. int active;
  272. int configured;
  273. u8 free;
  274. int irq;
  275. int rx_irq;
  276. int tx_irq;
  277. /* Protect the field .free, while checking if the mcbsp is in use */
  278. struct omap_mcbsp_platform_data *pdata;
  279. struct omap_mcbsp_st_data *st_data;
  280. struct omap_mcbsp_reg_cfg cfg_regs;
  281. struct snd_dmaengine_dai_dma_data dma_data[2];
  282. unsigned int dma_req[2];
  283. int dma_op_mode;
  284. u16 max_tx_thres;
  285. u16 max_rx_thres;
  286. void *reg_cache;
  287. int reg_cache_size;
  288. unsigned int fmt;
  289. unsigned int in_freq;
  290. int clk_div;
  291. int wlen;
  292. };
  293. void omap_mcbsp_config(struct omap_mcbsp *mcbsp,
  294. const struct omap_mcbsp_reg_cfg *config);
  295. void omap_mcbsp_set_tx_threshold(struct omap_mcbsp *mcbsp, u16 threshold);
  296. void omap_mcbsp_set_rx_threshold(struct omap_mcbsp *mcbsp, u16 threshold);
  297. u16 omap_mcbsp_get_tx_delay(struct omap_mcbsp *mcbsp);
  298. u16 omap_mcbsp_get_rx_delay(struct omap_mcbsp *mcbsp);
  299. int omap_mcbsp_get_dma_op_mode(struct omap_mcbsp *mcbsp);
  300. int omap_mcbsp_request(struct omap_mcbsp *mcbsp);
  301. void omap_mcbsp_free(struct omap_mcbsp *mcbsp);
  302. void omap_mcbsp_start(struct omap_mcbsp *mcbsp, int tx, int rx);
  303. void omap_mcbsp_stop(struct omap_mcbsp *mcbsp, int tx, int rx);
  304. /* McBSP functional clock source changing function */
  305. int omap2_mcbsp_set_clks_src(struct omap_mcbsp *mcbsp, u8 fck_src_id);
  306. /* Sidetone specific API */
  307. int omap_st_set_chgain(struct omap_mcbsp *mcbsp, int channel, s16 chgain);
  308. int omap_st_get_chgain(struct omap_mcbsp *mcbsp, int channel, s16 *chgain);
  309. int omap_st_enable(struct omap_mcbsp *mcbsp);
  310. int omap_st_disable(struct omap_mcbsp *mcbsp);
  311. int omap_st_is_enabled(struct omap_mcbsp *mcbsp);
  312. int omap_mcbsp_init(struct platform_device *pdev);
  313. void omap_mcbsp_sysfs_remove(struct omap_mcbsp *mcbsp);
  314. #endif /* __ASOC_MCBSP_H */