mcbsp.h 13 KB

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