mcbsp.h 11 KB

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