mcbsp.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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/completion.h>
  27. #include <linux/spinlock.h>
  28. #include <mach/hardware.h>
  29. #include <plat/clock.h>
  30. #define OMAP7XX_MCBSP1_BASE 0xfffb1000
  31. #define OMAP7XX_MCBSP2_BASE 0xfffb1800
  32. #define OMAP1510_MCBSP1_BASE 0xe1011800
  33. #define OMAP1510_MCBSP2_BASE 0xfffb1000
  34. #define OMAP1510_MCBSP3_BASE 0xe1017000
  35. #define OMAP1610_MCBSP1_BASE 0xe1011800
  36. #define OMAP1610_MCBSP2_BASE 0xfffb1000
  37. #define OMAP1610_MCBSP3_BASE 0xe1017000
  38. #define OMAP24XX_MCBSP1_BASE 0x48074000
  39. #define OMAP24XX_MCBSP2_BASE 0x48076000
  40. #define OMAP2430_MCBSP3_BASE 0x4808c000
  41. #define OMAP2430_MCBSP4_BASE 0x4808e000
  42. #define OMAP2430_MCBSP5_BASE 0x48096000
  43. #define OMAP34XX_MCBSP1_BASE 0x48074000
  44. #define OMAP34XX_MCBSP2_BASE 0x49022000
  45. #define OMAP34XX_MCBSP3_BASE 0x49024000
  46. #define OMAP34XX_MCBSP4_BASE 0x49026000
  47. #define OMAP34XX_MCBSP5_BASE 0x48096000
  48. #define OMAP44XX_MCBSP1_BASE 0x49022000
  49. #define OMAP44XX_MCBSP2_BASE 0x49024000
  50. #define OMAP44XX_MCBSP3_BASE 0x49026000
  51. #define OMAP44XX_MCBSP4_BASE 0x48074000
  52. #if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  53. #define OMAP_MCBSP_REG_DRR2 0x00
  54. #define OMAP_MCBSP_REG_DRR1 0x02
  55. #define OMAP_MCBSP_REG_DXR2 0x04
  56. #define OMAP_MCBSP_REG_DXR1 0x06
  57. #define OMAP_MCBSP_REG_SPCR2 0x08
  58. #define OMAP_MCBSP_REG_SPCR1 0x0a
  59. #define OMAP_MCBSP_REG_RCR2 0x0c
  60. #define OMAP_MCBSP_REG_RCR1 0x0e
  61. #define OMAP_MCBSP_REG_XCR2 0x10
  62. #define OMAP_MCBSP_REG_XCR1 0x12
  63. #define OMAP_MCBSP_REG_SRGR2 0x14
  64. #define OMAP_MCBSP_REG_SRGR1 0x16
  65. #define OMAP_MCBSP_REG_MCR2 0x18
  66. #define OMAP_MCBSP_REG_MCR1 0x1a
  67. #define OMAP_MCBSP_REG_RCERA 0x1c
  68. #define OMAP_MCBSP_REG_RCERB 0x1e
  69. #define OMAP_MCBSP_REG_XCERA 0x20
  70. #define OMAP_MCBSP_REG_XCERB 0x22
  71. #define OMAP_MCBSP_REG_PCR0 0x24
  72. #define OMAP_MCBSP_REG_RCERC 0x26
  73. #define OMAP_MCBSP_REG_RCERD 0x28
  74. #define OMAP_MCBSP_REG_XCERC 0x2A
  75. #define OMAP_MCBSP_REG_XCERD 0x2C
  76. #define OMAP_MCBSP_REG_RCERE 0x2E
  77. #define OMAP_MCBSP_REG_RCERF 0x30
  78. #define OMAP_MCBSP_REG_XCERE 0x32
  79. #define OMAP_MCBSP_REG_XCERF 0x34
  80. #define OMAP_MCBSP_REG_RCERG 0x36
  81. #define OMAP_MCBSP_REG_RCERH 0x38
  82. #define OMAP_MCBSP_REG_XCERG 0x3A
  83. #define OMAP_MCBSP_REG_XCERH 0x3C
  84. /* Dummy defines, these are not available on omap1 */
  85. #define OMAP_MCBSP_REG_XCCR 0x00
  86. #define OMAP_MCBSP_REG_RCCR 0x00
  87. #define AUDIO_MCBSP_DATAWRITE (OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1)
  88. #define AUDIO_MCBSP_DATAREAD (OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DRR1)
  89. #define AUDIO_MCBSP OMAP_MCBSP1
  90. #define AUDIO_DMA_TX OMAP_DMA_MCBSP1_TX
  91. #define AUDIO_DMA_RX OMAP_DMA_MCBSP1_RX
  92. #else
  93. #define OMAP_MCBSP_REG_DRR2 0x00
  94. #define OMAP_MCBSP_REG_DRR1 0x04
  95. #define OMAP_MCBSP_REG_DXR2 0x08
  96. #define OMAP_MCBSP_REG_DXR1 0x0C
  97. #define OMAP_MCBSP_REG_DRR 0x00
  98. #define OMAP_MCBSP_REG_DXR 0x08
  99. #define OMAP_MCBSP_REG_SPCR2 0x10
  100. #define OMAP_MCBSP_REG_SPCR1 0x14
  101. #define OMAP_MCBSP_REG_RCR2 0x18
  102. #define OMAP_MCBSP_REG_RCR1 0x1C
  103. #define OMAP_MCBSP_REG_XCR2 0x20
  104. #define OMAP_MCBSP_REG_XCR1 0x24
  105. #define OMAP_MCBSP_REG_SRGR2 0x28
  106. #define OMAP_MCBSP_REG_SRGR1 0x2C
  107. #define OMAP_MCBSP_REG_MCR2 0x30
  108. #define OMAP_MCBSP_REG_MCR1 0x34
  109. #define OMAP_MCBSP_REG_RCERA 0x38
  110. #define OMAP_MCBSP_REG_RCERB 0x3C
  111. #define OMAP_MCBSP_REG_XCERA 0x40
  112. #define OMAP_MCBSP_REG_XCERB 0x44
  113. #define OMAP_MCBSP_REG_PCR0 0x48
  114. #define OMAP_MCBSP_REG_RCERC 0x4C
  115. #define OMAP_MCBSP_REG_RCERD 0x50
  116. #define OMAP_MCBSP_REG_XCERC 0x54
  117. #define OMAP_MCBSP_REG_XCERD 0x58
  118. #define OMAP_MCBSP_REG_RCERE 0x5C
  119. #define OMAP_MCBSP_REG_RCERF 0x60
  120. #define OMAP_MCBSP_REG_XCERE 0x64
  121. #define OMAP_MCBSP_REG_XCERF 0x68
  122. #define OMAP_MCBSP_REG_RCERG 0x6C
  123. #define OMAP_MCBSP_REG_RCERH 0x70
  124. #define OMAP_MCBSP_REG_XCERG 0x74
  125. #define OMAP_MCBSP_REG_XCERH 0x78
  126. #define OMAP_MCBSP_REG_SYSCON 0x8C
  127. #define OMAP_MCBSP_REG_THRSH2 0x90
  128. #define OMAP_MCBSP_REG_THRSH1 0x94
  129. #define OMAP_MCBSP_REG_IRQST 0xA0
  130. #define OMAP_MCBSP_REG_IRQEN 0xA4
  131. #define OMAP_MCBSP_REG_WAKEUPEN 0xA8
  132. #define OMAP_MCBSP_REG_XCCR 0xAC
  133. #define OMAP_MCBSP_REG_RCCR 0xB0
  134. #define AUDIO_MCBSP_DATAWRITE (OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR1)
  135. #define AUDIO_MCBSP_DATAREAD (OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR1)
  136. #define AUDIO_MCBSP OMAP_MCBSP2
  137. #define AUDIO_DMA_TX OMAP24XX_DMA_MCBSP2_TX
  138. #define AUDIO_DMA_RX OMAP24XX_DMA_MCBSP2_RX
  139. #endif
  140. /************************** McBSP SPCR1 bit definitions ***********************/
  141. #define RRST 0x0001
  142. #define RRDY 0x0002
  143. #define RFULL 0x0004
  144. #define RSYNC_ERR 0x0008
  145. #define RINTM(value) ((value)<<4) /* bits 4:5 */
  146. #define ABIS 0x0040
  147. #define DXENA 0x0080
  148. #define CLKSTP(value) ((value)<<11) /* bits 11:12 */
  149. #define RJUST(value) ((value)<<13) /* bits 13:14 */
  150. #define ALB 0x8000
  151. #define DLB 0x8000
  152. /************************** McBSP SPCR2 bit definitions ***********************/
  153. #define XRST 0x0001
  154. #define XRDY 0x0002
  155. #define XEMPTY 0x0004
  156. #define XSYNC_ERR 0x0008
  157. #define XINTM(value) ((value)<<4) /* bits 4:5 */
  158. #define GRST 0x0040
  159. #define FRST 0x0080
  160. #define SOFT 0x0100
  161. #define FREE 0x0200
  162. /************************** McBSP PCR bit definitions *************************/
  163. #define CLKRP 0x0001
  164. #define CLKXP 0x0002
  165. #define FSRP 0x0004
  166. #define FSXP 0x0008
  167. #define DR_STAT 0x0010
  168. #define DX_STAT 0x0020
  169. #define CLKS_STAT 0x0040
  170. #define SCLKME 0x0080
  171. #define CLKRM 0x0100
  172. #define CLKXM 0x0200
  173. #define FSRM 0x0400
  174. #define FSXM 0x0800
  175. #define RIOEN 0x1000
  176. #define XIOEN 0x2000
  177. #define IDLE_EN 0x4000
  178. /************************** McBSP RCR1 bit definitions ************************/
  179. #define RWDLEN1(value) ((value)<<5) /* Bits 5:7 */
  180. #define RFRLEN1(value) ((value)<<8) /* Bits 8:14 */
  181. /************************** McBSP XCR1 bit definitions ************************/
  182. #define XWDLEN1(value) ((value)<<5) /* Bits 5:7 */
  183. #define XFRLEN1(value) ((value)<<8) /* Bits 8:14 */
  184. /*************************** McBSP RCR2 bit definitions ***********************/
  185. #define RDATDLY(value) (value) /* Bits 0:1 */
  186. #define RFIG 0x0004
  187. #define RCOMPAND(value) ((value)<<3) /* Bits 3:4 */
  188. #define RWDLEN2(value) ((value)<<5) /* Bits 5:7 */
  189. #define RFRLEN2(value) ((value)<<8) /* Bits 8:14 */
  190. #define RPHASE 0x8000
  191. /*************************** McBSP XCR2 bit definitions ***********************/
  192. #define XDATDLY(value) (value) /* Bits 0:1 */
  193. #define XFIG 0x0004
  194. #define XCOMPAND(value) ((value)<<3) /* Bits 3:4 */
  195. #define XWDLEN2(value) ((value)<<5) /* Bits 5:7 */
  196. #define XFRLEN2(value) ((value)<<8) /* Bits 8:14 */
  197. #define XPHASE 0x8000
  198. /************************* McBSP SRGR1 bit definitions ************************/
  199. #define CLKGDV(value) (value) /* Bits 0:7 */
  200. #define FWID(value) ((value)<<8) /* Bits 8:15 */
  201. /************************* McBSP SRGR2 bit definitions ************************/
  202. #define FPER(value) (value) /* Bits 0:11 */
  203. #define FSGM 0x1000
  204. #define CLKSM 0x2000
  205. #define CLKSP 0x4000
  206. #define GSYNC 0x8000
  207. /************************* McBSP MCR1 bit definitions *************************/
  208. #define RMCM 0x0001
  209. #define RCBLK(value) ((value)<<2) /* Bits 2:4 */
  210. #define RPABLK(value) ((value)<<5) /* Bits 5:6 */
  211. #define RPBBLK(value) ((value)<<7) /* Bits 7:8 */
  212. /************************* McBSP MCR2 bit definitions *************************/
  213. #define XMCM(value) (value) /* Bits 0:1 */
  214. #define XCBLK(value) ((value)<<2) /* Bits 2:4 */
  215. #define XPABLK(value) ((value)<<5) /* Bits 5:6 */
  216. #define XPBBLK(value) ((value)<<7) /* Bits 7:8 */
  217. /*********************** McBSP XCCR bit definitions *************************/
  218. #define EXTCLKGATE 0x8000
  219. #define PPCONNECT 0x4000
  220. #define DXENDLY(value) ((value)<<12) /* Bits 12:13 */
  221. #define XFULL_CYCLE 0x0800
  222. #define DILB 0x0020
  223. #define XDMAEN 0x0008
  224. #define XDISABLE 0x0001
  225. /********************** McBSP RCCR bit definitions *************************/
  226. #define RFULL_CYCLE 0x0800
  227. #define RDMAEN 0x0008
  228. #define RDISABLE 0x0001
  229. /********************** McBSP SYSCONFIG bit definitions ********************/
  230. #define CLOCKACTIVITY(value) ((value)<<8)
  231. #define SIDLEMODE(value) ((value)<<3)
  232. #define ENAWAKEUP 0x0004
  233. #define SOFTRST 0x0002
  234. /********************** McBSP DMA operating modes **************************/
  235. #define MCBSP_DMA_MODE_ELEMENT 0
  236. #define MCBSP_DMA_MODE_THRESHOLD 1
  237. #define MCBSP_DMA_MODE_FRAME 2
  238. /********************** McBSP WAKEUPEN bit definitions *********************/
  239. #define XEMPTYEOFEN 0x4000
  240. #define XRDYEN 0x0400
  241. #define XEOFEN 0x0200
  242. #define XFSXEN 0x0100
  243. #define XSYNCERREN 0x0080
  244. #define RRDYEN 0x0008
  245. #define REOFEN 0x0004
  246. #define RFSREN 0x0002
  247. #define RSYNCERREN 0x0001
  248. /* we don't do multichannel for now */
  249. struct omap_mcbsp_reg_cfg {
  250. u16 spcr2;
  251. u16 spcr1;
  252. u16 rcr2;
  253. u16 rcr1;
  254. u16 xcr2;
  255. u16 xcr1;
  256. u16 srgr2;
  257. u16 srgr1;
  258. u16 mcr2;
  259. u16 mcr1;
  260. u16 pcr0;
  261. u16 rcerc;
  262. u16 rcerd;
  263. u16 xcerc;
  264. u16 xcerd;
  265. u16 rcere;
  266. u16 rcerf;
  267. u16 xcere;
  268. u16 xcerf;
  269. u16 rcerg;
  270. u16 rcerh;
  271. u16 xcerg;
  272. u16 xcerh;
  273. u16 xccr;
  274. u16 rccr;
  275. };
  276. typedef enum {
  277. OMAP_MCBSP1 = 0,
  278. OMAP_MCBSP2,
  279. OMAP_MCBSP3,
  280. OMAP_MCBSP4,
  281. OMAP_MCBSP5
  282. } omap_mcbsp_id;
  283. typedef int __bitwise omap_mcbsp_io_type_t;
  284. #define OMAP_MCBSP_IRQ_IO ((__force omap_mcbsp_io_type_t) 1)
  285. #define OMAP_MCBSP_POLL_IO ((__force omap_mcbsp_io_type_t) 2)
  286. typedef enum {
  287. OMAP_MCBSP_WORD_8 = 0,
  288. OMAP_MCBSP_WORD_12,
  289. OMAP_MCBSP_WORD_16,
  290. OMAP_MCBSP_WORD_20,
  291. OMAP_MCBSP_WORD_24,
  292. OMAP_MCBSP_WORD_32,
  293. } omap_mcbsp_word_length;
  294. typedef enum {
  295. OMAP_MCBSP_CLK_RISING = 0,
  296. OMAP_MCBSP_CLK_FALLING,
  297. } omap_mcbsp_clk_polarity;
  298. typedef enum {
  299. OMAP_MCBSP_FS_ACTIVE_HIGH = 0,
  300. OMAP_MCBSP_FS_ACTIVE_LOW,
  301. } omap_mcbsp_fs_polarity;
  302. typedef enum {
  303. OMAP_MCBSP_CLK_STP_MODE_NO_DELAY = 0,
  304. OMAP_MCBSP_CLK_STP_MODE_DELAY,
  305. } omap_mcbsp_clk_stp_mode;
  306. /******* SPI specific mode **********/
  307. typedef enum {
  308. OMAP_MCBSP_SPI_MASTER = 0,
  309. OMAP_MCBSP_SPI_SLAVE,
  310. } omap_mcbsp_spi_mode;
  311. struct omap_mcbsp_spi_cfg {
  312. omap_mcbsp_spi_mode spi_mode;
  313. omap_mcbsp_clk_polarity rx_clock_polarity;
  314. omap_mcbsp_clk_polarity tx_clock_polarity;
  315. omap_mcbsp_fs_polarity fsx_polarity;
  316. u8 clk_div;
  317. omap_mcbsp_clk_stp_mode clk_stp_mode;
  318. omap_mcbsp_word_length word_length;
  319. };
  320. /* Platform specific configuration */
  321. struct omap_mcbsp_ops {
  322. void (*request)(unsigned int);
  323. void (*free)(unsigned int);
  324. };
  325. struct omap_mcbsp_platform_data {
  326. unsigned long phys_base;
  327. u8 dma_rx_sync, dma_tx_sync;
  328. u16 rx_irq, tx_irq;
  329. struct omap_mcbsp_ops *ops;
  330. #ifdef CONFIG_ARCH_OMAP3
  331. u16 buffer_size;
  332. #endif
  333. };
  334. struct omap_mcbsp {
  335. struct device *dev;
  336. unsigned long phys_base;
  337. void __iomem *io_base;
  338. u8 id;
  339. u8 free;
  340. omap_mcbsp_word_length rx_word_length;
  341. omap_mcbsp_word_length tx_word_length;
  342. omap_mcbsp_io_type_t io_type; /* IRQ or poll */
  343. /* IRQ based TX/RX */
  344. int rx_irq;
  345. int tx_irq;
  346. /* DMA stuff */
  347. u8 dma_rx_sync;
  348. short dma_rx_lch;
  349. u8 dma_tx_sync;
  350. short dma_tx_lch;
  351. /* Completion queues */
  352. struct completion tx_irq_completion;
  353. struct completion rx_irq_completion;
  354. struct completion tx_dma_completion;
  355. struct completion rx_dma_completion;
  356. /* Protect the field .free, while checking if the mcbsp is in use */
  357. spinlock_t lock;
  358. struct omap_mcbsp_platform_data *pdata;
  359. struct clk *iclk;
  360. struct clk *fclk;
  361. #ifdef CONFIG_ARCH_OMAP3
  362. int dma_op_mode;
  363. u16 max_tx_thres;
  364. u16 max_rx_thres;
  365. #endif
  366. void *reg_cache;
  367. };
  368. extern struct omap_mcbsp **mcbsp_ptr;
  369. extern int omap_mcbsp_count, omap_mcbsp_cache_size;
  370. int omap_mcbsp_init(void);
  371. void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
  372. int size);
  373. void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg * config);
  374. #ifdef CONFIG_ARCH_OMAP3
  375. void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold);
  376. void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold);
  377. u16 omap_mcbsp_get_max_tx_threshold(unsigned int id);
  378. u16 omap_mcbsp_get_max_rx_threshold(unsigned int id);
  379. int omap_mcbsp_get_dma_op_mode(unsigned int id);
  380. #else
  381. static inline void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold)
  382. { }
  383. static inline void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold)
  384. { }
  385. static inline u16 omap_mcbsp_get_max_tx_threshold(unsigned int id) { return 0; }
  386. static inline u16 omap_mcbsp_get_max_rx_threshold(unsigned int id) { return 0; }
  387. static inline int omap_mcbsp_get_dma_op_mode(unsigned int id) { return 0; }
  388. #endif
  389. int omap_mcbsp_request(unsigned int id);
  390. void omap_mcbsp_free(unsigned int id);
  391. void omap_mcbsp_start(unsigned int id, int tx, int rx);
  392. void omap_mcbsp_stop(unsigned int id, int tx, int rx);
  393. void omap_mcbsp_xmit_word(unsigned int id, u32 word);
  394. u32 omap_mcbsp_recv_word(unsigned int id);
  395. int omap_mcbsp_xmit_buffer(unsigned int id, dma_addr_t buffer, unsigned int length);
  396. int omap_mcbsp_recv_buffer(unsigned int id, dma_addr_t buffer, unsigned int length);
  397. int omap_mcbsp_spi_master_xmit_word_poll(unsigned int id, u32 word);
  398. int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 * word);
  399. /* SPI specific API */
  400. void omap_mcbsp_set_spi_mode(unsigned int id, const struct omap_mcbsp_spi_cfg * spi_cfg);
  401. /* Polled read/write functions */
  402. int omap_mcbsp_pollread(unsigned int id, u16 * buf);
  403. int omap_mcbsp_pollwrite(unsigned int id, u16 buf);
  404. int omap_mcbsp_set_io_type(unsigned int id, omap_mcbsp_io_type_t io_type);
  405. #endif