mcbsp.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. * linux/include/asm-arm/arch-omap/gpio.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 <asm/hardware.h>
  27. #define OMAP730_MCBSP1_BASE 0xfffb1000
  28. #define OMAP730_MCBSP2_BASE 0xfffb1800
  29. #define OMAP1510_MCBSP1_BASE 0xe1011800
  30. #define OMAP1510_MCBSP2_BASE 0xfffb1000
  31. #define OMAP1510_MCBSP3_BASE 0xe1017000
  32. #define OMAP1610_MCBSP1_BASE 0xe1011800
  33. #define OMAP1610_MCBSP2_BASE 0xfffb1000
  34. #define OMAP1610_MCBSP3_BASE 0xe1017000
  35. #define OMAP24XX_MCBSP1_BASE 0x48074000
  36. #define OMAP24XX_MCBSP2_BASE 0x48076000
  37. #if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP730)
  38. #define OMAP_MCBSP_REG_DRR2 0x00
  39. #define OMAP_MCBSP_REG_DRR1 0x02
  40. #define OMAP_MCBSP_REG_DXR2 0x04
  41. #define OMAP_MCBSP_REG_DXR1 0x06
  42. #define OMAP_MCBSP_REG_SPCR2 0x08
  43. #define OMAP_MCBSP_REG_SPCR1 0x0a
  44. #define OMAP_MCBSP_REG_RCR2 0x0c
  45. #define OMAP_MCBSP_REG_RCR1 0x0e
  46. #define OMAP_MCBSP_REG_XCR2 0x10
  47. #define OMAP_MCBSP_REG_XCR1 0x12
  48. #define OMAP_MCBSP_REG_SRGR2 0x14
  49. #define OMAP_MCBSP_REG_SRGR1 0x16
  50. #define OMAP_MCBSP_REG_MCR2 0x18
  51. #define OMAP_MCBSP_REG_MCR1 0x1a
  52. #define OMAP_MCBSP_REG_RCERA 0x1c
  53. #define OMAP_MCBSP_REG_RCERB 0x1e
  54. #define OMAP_MCBSP_REG_XCERA 0x20
  55. #define OMAP_MCBSP_REG_XCERB 0x22
  56. #define OMAP_MCBSP_REG_PCR0 0x24
  57. #define OMAP_MCBSP_REG_RCERC 0x26
  58. #define OMAP_MCBSP_REG_RCERD 0x28
  59. #define OMAP_MCBSP_REG_XCERC 0x2A
  60. #define OMAP_MCBSP_REG_XCERD 0x2C
  61. #define OMAP_MCBSP_REG_RCERE 0x2E
  62. #define OMAP_MCBSP_REG_RCERF 0x30
  63. #define OMAP_MCBSP_REG_XCERE 0x32
  64. #define OMAP_MCBSP_REG_XCERF 0x34
  65. #define OMAP_MCBSP_REG_RCERG 0x36
  66. #define OMAP_MCBSP_REG_RCERH 0x38
  67. #define OMAP_MCBSP_REG_XCERG 0x3A
  68. #define OMAP_MCBSP_REG_XCERH 0x3C
  69. #define OMAP_MAX_MCBSP_COUNT 3
  70. #define AUDIO_MCBSP_DATAWRITE (OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1)
  71. #define AUDIO_MCBSP_DATAREAD (OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DRR1)
  72. #define AUDIO_MCBSP OMAP_MCBSP1
  73. #define AUDIO_DMA_TX OMAP_DMA_MCBSP1_TX
  74. #define AUDIO_DMA_RX OMAP_DMA_MCBSP1_RX
  75. #elif defined(CONFIG_ARCH_OMAP24XX)
  76. #define OMAP_MCBSP_REG_DRR2 0x00
  77. #define OMAP_MCBSP_REG_DRR1 0x04
  78. #define OMAP_MCBSP_REG_DXR2 0x08
  79. #define OMAP_MCBSP_REG_DXR1 0x0C
  80. #define OMAP_MCBSP_REG_SPCR2 0x10
  81. #define OMAP_MCBSP_REG_SPCR1 0x14
  82. #define OMAP_MCBSP_REG_RCR2 0x18
  83. #define OMAP_MCBSP_REG_RCR1 0x1C
  84. #define OMAP_MCBSP_REG_XCR2 0x20
  85. #define OMAP_MCBSP_REG_XCR1 0x24
  86. #define OMAP_MCBSP_REG_SRGR2 0x28
  87. #define OMAP_MCBSP_REG_SRGR1 0x2C
  88. #define OMAP_MCBSP_REG_MCR2 0x30
  89. #define OMAP_MCBSP_REG_MCR1 0x34
  90. #define OMAP_MCBSP_REG_RCERA 0x38
  91. #define OMAP_MCBSP_REG_RCERB 0x3C
  92. #define OMAP_MCBSP_REG_XCERA 0x40
  93. #define OMAP_MCBSP_REG_XCERB 0x44
  94. #define OMAP_MCBSP_REG_PCR0 0x48
  95. #define OMAP_MCBSP_REG_RCERC 0x4C
  96. #define OMAP_MCBSP_REG_RCERD 0x50
  97. #define OMAP_MCBSP_REG_XCERC 0x54
  98. #define OMAP_MCBSP_REG_XCERD 0x58
  99. #define OMAP_MCBSP_REG_RCERE 0x5C
  100. #define OMAP_MCBSP_REG_RCERF 0x60
  101. #define OMAP_MCBSP_REG_XCERE 0x64
  102. #define OMAP_MCBSP_REG_XCERF 0x68
  103. #define OMAP_MCBSP_REG_RCERG 0x6C
  104. #define OMAP_MCBSP_REG_RCERH 0x70
  105. #define OMAP_MCBSP_REG_XCERG 0x74
  106. #define OMAP_MCBSP_REG_XCERH 0x78
  107. #define OMAP_MAX_MCBSP_COUNT 2
  108. #define AUDIO_MCBSP_DATAWRITE (OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR1)
  109. #define AUDIO_MCBSP_DATAREAD (OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR1)
  110. #define AUDIO_MCBSP OMAP_MCBSP2
  111. #define AUDIO_DMA_TX OMAP24XX_DMA_MCBSP2_TX
  112. #define AUDIO_DMA_RX OMAP24XX_DMA_MCBSP2_RX
  113. #endif
  114. #define OMAP_MCBSP_READ(base, reg) __raw_readw((base) + OMAP_MCBSP_REG_##reg)
  115. #define OMAP_MCBSP_WRITE(base, reg, val) __raw_writew((val), (base) + OMAP_MCBSP_REG_##reg)
  116. /************************** McBSP SPCR1 bit definitions ***********************/
  117. #define RRST 0x0001
  118. #define RRDY 0x0002
  119. #define RFULL 0x0004
  120. #define RSYNC_ERR 0x0008
  121. #define RINTM(value) ((value)<<4) /* bits 4:5 */
  122. #define ABIS 0x0040
  123. #define DXENA 0x0080
  124. #define CLKSTP(value) ((value)<<11) /* bits 11:12 */
  125. #define RJUST(value) ((value)<<13) /* bits 13:14 */
  126. #define DLB 0x8000
  127. /************************** McBSP SPCR2 bit definitions ***********************/
  128. #define XRST 0x0001
  129. #define XRDY 0x0002
  130. #define XEMPTY 0x0004
  131. #define XSYNC_ERR 0x0008
  132. #define XINTM(value) ((value)<<4) /* bits 4:5 */
  133. #define GRST 0x0040
  134. #define FRST 0x0080
  135. #define SOFT 0x0100
  136. #define FREE 0x0200
  137. /************************** McBSP PCR bit definitions *************************/
  138. #define CLKRP 0x0001
  139. #define CLKXP 0x0002
  140. #define FSRP 0x0004
  141. #define FSXP 0x0008
  142. #define DR_STAT 0x0010
  143. #define DX_STAT 0x0020
  144. #define CLKS_STAT 0x0040
  145. #define SCLKME 0x0080
  146. #define CLKRM 0x0100
  147. #define CLKXM 0x0200
  148. #define FSRM 0x0400
  149. #define FSXM 0x0800
  150. #define RIOEN 0x1000
  151. #define XIOEN 0x2000
  152. #define IDLE_EN 0x4000
  153. /************************** McBSP RCR1 bit definitions ************************/
  154. #define RWDLEN1(value) ((value)<<5) /* Bits 5:7 */
  155. #define RFRLEN1(value) ((value)<<8) /* Bits 8:14 */
  156. /************************** McBSP XCR1 bit definitions ************************/
  157. #define XWDLEN1(value) ((value)<<5) /* Bits 5:7 */
  158. #define XFRLEN1(value) ((value)<<8) /* Bits 8:14 */
  159. /*************************** McBSP RCR2 bit definitions ***********************/
  160. #define RDATDLY(value) (value) /* Bits 0:1 */
  161. #define RFIG 0x0004
  162. #define RCOMPAND(value) ((value)<<3) /* Bits 3:4 */
  163. #define RWDLEN2(value) ((value)<<5) /* Bits 5:7 */
  164. #define RFRLEN2(value) ((value)<<8) /* Bits 8:14 */
  165. #define RPHASE 0x8000
  166. /*************************** McBSP XCR2 bit definitions ***********************/
  167. #define XDATDLY(value) (value) /* Bits 0:1 */
  168. #define XFIG 0x0004
  169. #define XCOMPAND(value) ((value)<<3) /* Bits 3:4 */
  170. #define XWDLEN2(value) ((value)<<5) /* Bits 5:7 */
  171. #define XFRLEN2(value) ((value)<<8) /* Bits 8:14 */
  172. #define XPHASE 0x8000
  173. /************************* McBSP SRGR1 bit definitions ************************/
  174. #define CLKGDV(value) (value) /* Bits 0:7 */
  175. #define FWID(value) ((value)<<8) /* Bits 8:15 */
  176. /************************* McBSP SRGR2 bit definitions ************************/
  177. #define FPER(value) (value) /* Bits 0:11 */
  178. #define FSGM 0x1000
  179. #define CLKSM 0x2000
  180. #define CLKSP 0x4000
  181. #define GSYNC 0x8000
  182. /************************* McBSP MCR1 bit definitions *************************/
  183. #define RMCM 0x0001
  184. #define RCBLK(value) ((value)<<2) /* Bits 2:4 */
  185. #define RPABLK(value) ((value)<<5) /* Bits 5:6 */
  186. #define RPBBLK(value) ((value)<<7) /* Bits 7:8 */
  187. /************************* McBSP MCR2 bit definitions *************************/
  188. #define XMCM(value) (value) /* Bits 0:1 */
  189. #define XCBLK(value) ((value)<<2) /* Bits 2:4 */
  190. #define XPABLK(value) ((value)<<5) /* Bits 5:6 */
  191. #define XPBBLK(value) ((value)<<7) /* Bits 7:8 */
  192. /* we don't do multichannel for now */
  193. struct omap_mcbsp_reg_cfg {
  194. u16 spcr2;
  195. u16 spcr1;
  196. u16 rcr2;
  197. u16 rcr1;
  198. u16 xcr2;
  199. u16 xcr1;
  200. u16 srgr2;
  201. u16 srgr1;
  202. u16 mcr2;
  203. u16 mcr1;
  204. u16 pcr0;
  205. u16 rcerc;
  206. u16 rcerd;
  207. u16 xcerc;
  208. u16 xcerd;
  209. u16 rcere;
  210. u16 rcerf;
  211. u16 xcere;
  212. u16 xcerf;
  213. u16 rcerg;
  214. u16 rcerh;
  215. u16 xcerg;
  216. u16 xcerh;
  217. };
  218. typedef enum {
  219. OMAP_MCBSP1 = 0,
  220. OMAP_MCBSP2,
  221. OMAP_MCBSP3,
  222. } omap_mcbsp_id;
  223. typedef int __bitwise omap_mcbsp_io_type_t;
  224. #define OMAP_MCBSP_IRQ_IO ((__force omap_mcbsp_io_type_t) 1)
  225. #define OMAP_MCBSP_POLL_IO ((__force omap_mcbsp_io_type_t) 2)
  226. typedef enum {
  227. OMAP_MCBSP_WORD_8 = 0,
  228. OMAP_MCBSP_WORD_12,
  229. OMAP_MCBSP_WORD_16,
  230. OMAP_MCBSP_WORD_20,
  231. OMAP_MCBSP_WORD_24,
  232. OMAP_MCBSP_WORD_32,
  233. } omap_mcbsp_word_length;
  234. typedef enum {
  235. OMAP_MCBSP_CLK_RISING = 0,
  236. OMAP_MCBSP_CLK_FALLING,
  237. } omap_mcbsp_clk_polarity;
  238. typedef enum {
  239. OMAP_MCBSP_FS_ACTIVE_HIGH = 0,
  240. OMAP_MCBSP_FS_ACTIVE_LOW,
  241. } omap_mcbsp_fs_polarity;
  242. typedef enum {
  243. OMAP_MCBSP_CLK_STP_MODE_NO_DELAY = 0,
  244. OMAP_MCBSP_CLK_STP_MODE_DELAY,
  245. } omap_mcbsp_clk_stp_mode;
  246. /******* SPI specific mode **********/
  247. typedef enum {
  248. OMAP_MCBSP_SPI_MASTER = 0,
  249. OMAP_MCBSP_SPI_SLAVE,
  250. } omap_mcbsp_spi_mode;
  251. struct omap_mcbsp_spi_cfg {
  252. omap_mcbsp_spi_mode spi_mode;
  253. omap_mcbsp_clk_polarity rx_clock_polarity;
  254. omap_mcbsp_clk_polarity tx_clock_polarity;
  255. omap_mcbsp_fs_polarity fsx_polarity;
  256. u8 clk_div;
  257. omap_mcbsp_clk_stp_mode clk_stp_mode;
  258. omap_mcbsp_word_length word_length;
  259. };
  260. void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg * config);
  261. int omap_mcbsp_request(unsigned int id);
  262. void omap_mcbsp_free(unsigned int id);
  263. void omap_mcbsp_start(unsigned int id);
  264. void omap_mcbsp_stop(unsigned int id);
  265. void omap_mcbsp_xmit_word(unsigned int id, u32 word);
  266. u32 omap_mcbsp_recv_word(unsigned int id);
  267. int omap_mcbsp_xmit_buffer(unsigned int id, dma_addr_t buffer, unsigned int length);
  268. int omap_mcbsp_recv_buffer(unsigned int id, dma_addr_t buffer, unsigned int length);
  269. int omap_mcbsp_spi_master_xmit_word_poll(unsigned int id, u32 word);
  270. int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 * word);
  271. /* SPI specific API */
  272. void omap_mcbsp_set_spi_mode(unsigned int id, const struct omap_mcbsp_spi_cfg * spi_cfg);
  273. /* Polled read/write functions */
  274. int omap_mcbsp_pollread(unsigned int id, u16 * buf);
  275. int omap_mcbsp_pollwrite(unsigned int id, u16 buf);
  276. #endif