mcbsp.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. /*
  2. * arch/arm/plat-omap/include/mach/mcbsp.h
  3. *
  4. * Defines for Multi-Channel Buffered Serial Port
  5. *
  6. * Copyright (C) 2002 RidgeRun, Inc.
  7. * Author: Steve Johnson
  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 __ASM_ARCH_OMAP_MCBSP_H
  25. #define __ASM_ARCH_OMAP_MCBSP_H
  26. #include <linux/spinlock.h>
  27. #include <linux/clk.h>
  28. /* macro for building platform_device for McBSP ports */
  29. #define OMAP_MCBSP_PLATFORM_DEVICE(port_nr) \
  30. static struct platform_device omap_mcbsp##port_nr = { \
  31. .name = "omap-mcbsp-dai", \
  32. .id = port_nr - 1, \
  33. }
  34. #define MCBSP_CONFIG_TYPE2 0x2
  35. #define MCBSP_CONFIG_TYPE3 0x3
  36. #define MCBSP_CONFIG_TYPE4 0x4
  37. /* McBSP register numbers. Register address offset = num * reg_step */
  38. enum {
  39. /* Common registers */
  40. OMAP_MCBSP_REG_SPCR2 = 4,
  41. OMAP_MCBSP_REG_SPCR1,
  42. OMAP_MCBSP_REG_RCR2,
  43. OMAP_MCBSP_REG_RCR1,
  44. OMAP_MCBSP_REG_XCR2,
  45. OMAP_MCBSP_REG_XCR1,
  46. OMAP_MCBSP_REG_SRGR2,
  47. OMAP_MCBSP_REG_SRGR1,
  48. OMAP_MCBSP_REG_MCR2,
  49. OMAP_MCBSP_REG_MCR1,
  50. OMAP_MCBSP_REG_RCERA,
  51. OMAP_MCBSP_REG_RCERB,
  52. OMAP_MCBSP_REG_XCERA,
  53. OMAP_MCBSP_REG_XCERB,
  54. OMAP_MCBSP_REG_PCR0,
  55. OMAP_MCBSP_REG_RCERC,
  56. OMAP_MCBSP_REG_RCERD,
  57. OMAP_MCBSP_REG_XCERC,
  58. OMAP_MCBSP_REG_XCERD,
  59. OMAP_MCBSP_REG_RCERE,
  60. OMAP_MCBSP_REG_RCERF,
  61. OMAP_MCBSP_REG_XCERE,
  62. OMAP_MCBSP_REG_XCERF,
  63. OMAP_MCBSP_REG_RCERG,
  64. OMAP_MCBSP_REG_RCERH,
  65. OMAP_MCBSP_REG_XCERG,
  66. OMAP_MCBSP_REG_XCERH,
  67. /* OMAP1-OMAP2420 registers */
  68. OMAP_MCBSP_REG_DRR2 = 0,
  69. OMAP_MCBSP_REG_DRR1,
  70. OMAP_MCBSP_REG_DXR2,
  71. OMAP_MCBSP_REG_DXR1,
  72. /* OMAP2430 and onwards */
  73. OMAP_MCBSP_REG_DRR = 0,
  74. OMAP_MCBSP_REG_DXR = 2,
  75. OMAP_MCBSP_REG_SYSCON = 35,
  76. OMAP_MCBSP_REG_THRSH2,
  77. OMAP_MCBSP_REG_THRSH1,
  78. OMAP_MCBSP_REG_IRQST = 40,
  79. OMAP_MCBSP_REG_IRQEN,
  80. OMAP_MCBSP_REG_WAKEUPEN,
  81. OMAP_MCBSP_REG_XCCR,
  82. OMAP_MCBSP_REG_RCCR,
  83. OMAP_MCBSP_REG_XBUFFSTAT,
  84. OMAP_MCBSP_REG_RBUFFSTAT,
  85. OMAP_MCBSP_REG_SSELCR,
  86. };
  87. /* OMAP3 sidetone control registers */
  88. #define OMAP_ST_REG_REV 0x00
  89. #define OMAP_ST_REG_SYSCONFIG 0x10
  90. #define OMAP_ST_REG_IRQSTATUS 0x18
  91. #define OMAP_ST_REG_IRQENABLE 0x1C
  92. #define OMAP_ST_REG_SGAINCR 0x24
  93. #define OMAP_ST_REG_SFIRCR 0x28
  94. #define OMAP_ST_REG_SSELCR 0x2C
  95. /************************** McBSP SPCR1 bit definitions ***********************/
  96. #define RRST 0x0001
  97. #define RRDY 0x0002
  98. #define RFULL 0x0004
  99. #define RSYNC_ERR 0x0008
  100. #define RINTM(value) ((value)<<4) /* bits 4:5 */
  101. #define ABIS 0x0040
  102. #define DXENA 0x0080
  103. #define CLKSTP(value) ((value)<<11) /* bits 11:12 */
  104. #define RJUST(value) ((value)<<13) /* bits 13:14 */
  105. #define ALB 0x8000
  106. #define DLB 0x8000
  107. /************************** McBSP SPCR2 bit definitions ***********************/
  108. #define XRST 0x0001
  109. #define XRDY 0x0002
  110. #define XEMPTY 0x0004
  111. #define XSYNC_ERR 0x0008
  112. #define XINTM(value) ((value)<<4) /* bits 4:5 */
  113. #define GRST 0x0040
  114. #define FRST 0x0080
  115. #define SOFT 0x0100
  116. #define FREE 0x0200
  117. /************************** McBSP PCR bit definitions *************************/
  118. #define CLKRP 0x0001
  119. #define CLKXP 0x0002
  120. #define FSRP 0x0004
  121. #define FSXP 0x0008
  122. #define DR_STAT 0x0010
  123. #define DX_STAT 0x0020
  124. #define CLKS_STAT 0x0040
  125. #define SCLKME 0x0080
  126. #define CLKRM 0x0100
  127. #define CLKXM 0x0200
  128. #define FSRM 0x0400
  129. #define FSXM 0x0800
  130. #define RIOEN 0x1000
  131. #define XIOEN 0x2000
  132. #define IDLE_EN 0x4000
  133. /************************** McBSP RCR1 bit definitions ************************/
  134. #define RWDLEN1(value) ((value)<<5) /* Bits 5:7 */
  135. #define RFRLEN1(value) ((value)<<8) /* Bits 8:14 */
  136. /************************** McBSP XCR1 bit definitions ************************/
  137. #define XWDLEN1(value) ((value)<<5) /* Bits 5:7 */
  138. #define XFRLEN1(value) ((value)<<8) /* Bits 8:14 */
  139. /*************************** McBSP RCR2 bit definitions ***********************/
  140. #define RDATDLY(value) (value) /* Bits 0:1 */
  141. #define RFIG 0x0004
  142. #define RCOMPAND(value) ((value)<<3) /* Bits 3:4 */
  143. #define RWDLEN2(value) ((value)<<5) /* Bits 5:7 */
  144. #define RFRLEN2(value) ((value)<<8) /* Bits 8:14 */
  145. #define RPHASE 0x8000
  146. /*************************** McBSP XCR2 bit definitions ***********************/
  147. #define XDATDLY(value) (value) /* Bits 0:1 */
  148. #define XFIG 0x0004
  149. #define XCOMPAND(value) ((value)<<3) /* Bits 3:4 */
  150. #define XWDLEN2(value) ((value)<<5) /* Bits 5:7 */
  151. #define XFRLEN2(value) ((value)<<8) /* Bits 8:14 */
  152. #define XPHASE 0x8000
  153. /************************* McBSP SRGR1 bit definitions ************************/
  154. #define CLKGDV(value) (value) /* Bits 0:7 */
  155. #define FWID(value) ((value)<<8) /* Bits 8:15 */
  156. /************************* McBSP SRGR2 bit definitions ************************/
  157. #define FPER(value) (value) /* Bits 0:11 */
  158. #define FSGM 0x1000
  159. #define CLKSM 0x2000
  160. #define CLKSP 0x4000
  161. #define GSYNC 0x8000
  162. /************************* McBSP MCR1 bit definitions *************************/
  163. #define RMCM 0x0001
  164. #define RCBLK(value) ((value)<<2) /* Bits 2:4 */
  165. #define RPABLK(value) ((value)<<5) /* Bits 5:6 */
  166. #define RPBBLK(value) ((value)<<7) /* Bits 7:8 */
  167. /************************* McBSP MCR2 bit definitions *************************/
  168. #define XMCM(value) (value) /* Bits 0:1 */
  169. #define XCBLK(value) ((value)<<2) /* Bits 2:4 */
  170. #define XPABLK(value) ((value)<<5) /* Bits 5:6 */
  171. #define XPBBLK(value) ((value)<<7) /* Bits 7:8 */
  172. /*********************** McBSP XCCR bit definitions *************************/
  173. #define EXTCLKGATE 0x8000
  174. #define PPCONNECT 0x4000
  175. #define DXENDLY(value) ((value)<<12) /* Bits 12:13 */
  176. #define XFULL_CYCLE 0x0800
  177. #define DILB 0x0020
  178. #define XDMAEN 0x0008
  179. #define XDISABLE 0x0001
  180. /********************** McBSP RCCR bit definitions *************************/
  181. #define RFULL_CYCLE 0x0800
  182. #define RDMAEN 0x0008
  183. #define RDISABLE 0x0001
  184. /********************** McBSP SYSCONFIG bit definitions ********************/
  185. #define CLOCKACTIVITY(value) ((value)<<8)
  186. #define SIDLEMODE(value) ((value)<<3)
  187. #define ENAWAKEUP 0x0004
  188. #define SOFTRST 0x0002
  189. /********************** McBSP SSELCR bit definitions ***********************/
  190. #define SIDETONEEN 0x0400
  191. /********************** McBSP Sidetone SYSCONFIG bit definitions ***********/
  192. #define ST_AUTOIDLE 0x0001
  193. /********************** McBSP Sidetone SGAINCR bit definitions *************/
  194. #define ST_CH1GAIN(value) ((value<<16)) /* Bits 16:31 */
  195. #define ST_CH0GAIN(value) (value) /* Bits 0:15 */
  196. /********************** McBSP Sidetone SFIRCR bit definitions **************/
  197. #define ST_FIRCOEFF(value) (value) /* Bits 0:15 */
  198. /********************** McBSP Sidetone SSELCR bit definitions **************/
  199. #define ST_COEFFWRDONE 0x0004
  200. #define ST_COEFFWREN 0x0002
  201. #define ST_SIDETONEEN 0x0001
  202. /********************** McBSP DMA operating modes **************************/
  203. #define MCBSP_DMA_MODE_ELEMENT 0
  204. #define MCBSP_DMA_MODE_THRESHOLD 1
  205. #define MCBSP_DMA_MODE_FRAME 2
  206. /********************** McBSP WAKEUPEN bit definitions *********************/
  207. #define XEMPTYEOFEN 0x4000
  208. #define XRDYEN 0x0400
  209. #define XEOFEN 0x0200
  210. #define XFSXEN 0x0100
  211. #define XSYNCERREN 0x0080
  212. #define RRDYEN 0x0008
  213. #define REOFEN 0x0004
  214. #define RFSREN 0x0002
  215. #define RSYNCERREN 0x0001
  216. /* CLKR signal muxing options */
  217. #define CLKR_SRC_CLKR 0
  218. #define CLKR_SRC_CLKX 1
  219. /* FSR signal muxing options */
  220. #define FSR_SRC_FSR 0
  221. #define FSR_SRC_FSX 1
  222. /* McBSP functional clock sources */
  223. #define MCBSP_CLKS_PRCM_SRC 0
  224. #define MCBSP_CLKS_PAD_SRC 1
  225. /* we don't do multichannel for now */
  226. struct omap_mcbsp_reg_cfg {
  227. u16 spcr2;
  228. u16 spcr1;
  229. u16 rcr2;
  230. u16 rcr1;
  231. u16 xcr2;
  232. u16 xcr1;
  233. u16 srgr2;
  234. u16 srgr1;
  235. u16 mcr2;
  236. u16 mcr1;
  237. u16 pcr0;
  238. u16 rcerc;
  239. u16 rcerd;
  240. u16 xcerc;
  241. u16 xcerd;
  242. u16 rcere;
  243. u16 rcerf;
  244. u16 xcere;
  245. u16 xcerf;
  246. u16 rcerg;
  247. u16 rcerh;
  248. u16 xcerg;
  249. u16 xcerh;
  250. u16 xccr;
  251. u16 rccr;
  252. };
  253. typedef enum {
  254. OMAP_MCBSP_WORD_8 = 0,
  255. OMAP_MCBSP_WORD_12,
  256. OMAP_MCBSP_WORD_16,
  257. OMAP_MCBSP_WORD_20,
  258. OMAP_MCBSP_WORD_24,
  259. OMAP_MCBSP_WORD_32,
  260. } omap_mcbsp_word_length;
  261. /* Platform specific configuration */
  262. struct omap_mcbsp_ops {
  263. void (*request)(unsigned int);
  264. void (*free)(unsigned int);
  265. };
  266. struct omap_mcbsp_platform_data {
  267. struct omap_mcbsp_ops *ops;
  268. u16 buffer_size;
  269. u8 reg_size;
  270. u8 reg_step;
  271. /* McBSP platform and instance specific features */
  272. bool has_wakeup; /* Wakeup capability */
  273. bool has_ccr; /* Transceiver has configuration control registers */
  274. int (*enable_st_clock)(unsigned int, bool);
  275. int (*set_clk_src)(struct device *dev, struct clk *clk, const char *src);
  276. int (*mux_signal)(struct device *dev, const char *signal, const char *src);
  277. };
  278. struct omap_mcbsp_st_data {
  279. void __iomem *io_base_st;
  280. bool running;
  281. bool enabled;
  282. s16 taps[128]; /* Sidetone filter coefficients */
  283. int nr_taps; /* Number of filter coefficients in use */
  284. s16 ch0gain;
  285. s16 ch1gain;
  286. };
  287. struct omap_mcbsp {
  288. struct device *dev;
  289. unsigned long phys_base;
  290. unsigned long phys_dma_base;
  291. void __iomem *io_base;
  292. u8 id;
  293. u8 free;
  294. int rx_irq;
  295. int tx_irq;
  296. /* DMA stuff */
  297. u8 dma_rx_sync;
  298. u8 dma_tx_sync;
  299. /* Protect the field .free, while checking if the mcbsp is in use */
  300. spinlock_t lock;
  301. struct omap_mcbsp_platform_data *pdata;
  302. struct clk *fclk;
  303. struct omap_mcbsp_st_data *st_data;
  304. int dma_op_mode;
  305. u16 max_tx_thres;
  306. u16 max_rx_thres;
  307. void *reg_cache;
  308. int reg_cache_size;
  309. };
  310. /**
  311. * omap_mcbsp_dev_attr - OMAP McBSP device attributes for omap_hwmod
  312. * @sidetone: name of the sidetone device
  313. */
  314. struct omap_mcbsp_dev_attr {
  315. const char *sidetone;
  316. };
  317. extern struct omap_mcbsp **mcbsp_ptr;
  318. extern int omap_mcbsp_count;
  319. int omap_mcbsp_init(void);
  320. void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg * config);
  321. void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold);
  322. void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold);
  323. u16 omap_mcbsp_get_max_tx_threshold(unsigned int id);
  324. u16 omap_mcbsp_get_max_rx_threshold(unsigned int id);
  325. u16 omap_mcbsp_get_fifo_size(unsigned int id);
  326. u16 omap_mcbsp_get_tx_delay(unsigned int id);
  327. u16 omap_mcbsp_get_rx_delay(unsigned int id);
  328. int omap_mcbsp_get_dma_op_mode(unsigned int id);
  329. int omap_mcbsp_request(unsigned int id);
  330. void omap_mcbsp_free(unsigned int id);
  331. void omap_mcbsp_start(unsigned int id, int tx, int rx);
  332. void omap_mcbsp_stop(unsigned int id, int tx, int rx);
  333. /* McBSP functional clock source changing function */
  334. extern int omap2_mcbsp_set_clks_src(u8 id, u8 fck_src_id);
  335. /* McBSP signal muxing API */
  336. void omap2_mcbsp1_mux_clkr_src(u8 mux);
  337. void omap2_mcbsp1_mux_fsr_src(u8 mux);
  338. int omap_mcbsp_dma_ch_params(unsigned int id, unsigned int stream);
  339. int omap_mcbsp_dma_reg_params(unsigned int id, unsigned int stream);
  340. /* Sidetone specific API */
  341. int omap_st_set_chgain(unsigned int id, int channel, s16 chgain);
  342. int omap_st_get_chgain(unsigned int id, int channel, s16 *chgain);
  343. int omap_st_enable(unsigned int id);
  344. int omap_st_disable(unsigned int id);
  345. int omap_st_is_enabled(unsigned int id);
  346. #endif