mcbsp.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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 <mach/clock.h>
  30. #define OMAP730_MCBSP1_BASE 0xfffb1000
  31. #define OMAP730_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 OMAP34XX_MCBSP1_BASE 0x48074000
  41. #define OMAP34XX_MCBSP2_BASE 0x49022000
  42. #if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP730)
  43. #define OMAP_MCBSP_REG_DRR2 0x00
  44. #define OMAP_MCBSP_REG_DRR1 0x02
  45. #define OMAP_MCBSP_REG_DXR2 0x04
  46. #define OMAP_MCBSP_REG_DXR1 0x06
  47. #define OMAP_MCBSP_REG_SPCR2 0x08
  48. #define OMAP_MCBSP_REG_SPCR1 0x0a
  49. #define OMAP_MCBSP_REG_RCR2 0x0c
  50. #define OMAP_MCBSP_REG_RCR1 0x0e
  51. #define OMAP_MCBSP_REG_XCR2 0x10
  52. #define OMAP_MCBSP_REG_XCR1 0x12
  53. #define OMAP_MCBSP_REG_SRGR2 0x14
  54. #define OMAP_MCBSP_REG_SRGR1 0x16
  55. #define OMAP_MCBSP_REG_MCR2 0x18
  56. #define OMAP_MCBSP_REG_MCR1 0x1a
  57. #define OMAP_MCBSP_REG_RCERA 0x1c
  58. #define OMAP_MCBSP_REG_RCERB 0x1e
  59. #define OMAP_MCBSP_REG_XCERA 0x20
  60. #define OMAP_MCBSP_REG_XCERB 0x22
  61. #define OMAP_MCBSP_REG_PCR0 0x24
  62. #define OMAP_MCBSP_REG_RCERC 0x26
  63. #define OMAP_MCBSP_REG_RCERD 0x28
  64. #define OMAP_MCBSP_REG_XCERC 0x2A
  65. #define OMAP_MCBSP_REG_XCERD 0x2C
  66. #define OMAP_MCBSP_REG_RCERE 0x2E
  67. #define OMAP_MCBSP_REG_RCERF 0x30
  68. #define OMAP_MCBSP_REG_XCERE 0x32
  69. #define OMAP_MCBSP_REG_XCERF 0x34
  70. #define OMAP_MCBSP_REG_RCERG 0x36
  71. #define OMAP_MCBSP_REG_RCERH 0x38
  72. #define OMAP_MCBSP_REG_XCERG 0x3A
  73. #define OMAP_MCBSP_REG_XCERH 0x3C
  74. #define OMAP_MAX_MCBSP_COUNT 3
  75. #define MAX_MCBSP_CLOCKS 3
  76. #define AUDIO_MCBSP_DATAWRITE (OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1)
  77. #define AUDIO_MCBSP_DATAREAD (OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DRR1)
  78. #define AUDIO_MCBSP OMAP_MCBSP1
  79. #define AUDIO_DMA_TX OMAP_DMA_MCBSP1_TX
  80. #define AUDIO_DMA_RX OMAP_DMA_MCBSP1_RX
  81. #elif defined(CONFIG_ARCH_OMAP24XX)
  82. #define OMAP_MCBSP_REG_DRR2 0x00
  83. #define OMAP_MCBSP_REG_DRR1 0x04
  84. #define OMAP_MCBSP_REG_DXR2 0x08
  85. #define OMAP_MCBSP_REG_DXR1 0x0C
  86. #define OMAP_MCBSP_REG_SPCR2 0x10
  87. #define OMAP_MCBSP_REG_SPCR1 0x14
  88. #define OMAP_MCBSP_REG_RCR2 0x18
  89. #define OMAP_MCBSP_REG_RCR1 0x1C
  90. #define OMAP_MCBSP_REG_XCR2 0x20
  91. #define OMAP_MCBSP_REG_XCR1 0x24
  92. #define OMAP_MCBSP_REG_SRGR2 0x28
  93. #define OMAP_MCBSP_REG_SRGR1 0x2C
  94. #define OMAP_MCBSP_REG_MCR2 0x30
  95. #define OMAP_MCBSP_REG_MCR1 0x34
  96. #define OMAP_MCBSP_REG_RCERA 0x38
  97. #define OMAP_MCBSP_REG_RCERB 0x3C
  98. #define OMAP_MCBSP_REG_XCERA 0x40
  99. #define OMAP_MCBSP_REG_XCERB 0x44
  100. #define OMAP_MCBSP_REG_PCR0 0x48
  101. #define OMAP_MCBSP_REG_RCERC 0x4C
  102. #define OMAP_MCBSP_REG_RCERD 0x50
  103. #define OMAP_MCBSP_REG_XCERC 0x54
  104. #define OMAP_MCBSP_REG_XCERD 0x58
  105. #define OMAP_MCBSP_REG_RCERE 0x5C
  106. #define OMAP_MCBSP_REG_RCERF 0x60
  107. #define OMAP_MCBSP_REG_XCERE 0x64
  108. #define OMAP_MCBSP_REG_XCERF 0x68
  109. #define OMAP_MCBSP_REG_RCERG 0x6C
  110. #define OMAP_MCBSP_REG_RCERH 0x70
  111. #define OMAP_MCBSP_REG_XCERG 0x74
  112. #define OMAP_MCBSP_REG_XCERH 0x78
  113. #define OMAP_MAX_MCBSP_COUNT 2
  114. #define MAX_MCBSP_CLOCKS 2
  115. #define AUDIO_MCBSP_DATAWRITE (OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR1)
  116. #define AUDIO_MCBSP_DATAREAD (OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR1)
  117. #define AUDIO_MCBSP OMAP_MCBSP2
  118. #define AUDIO_DMA_TX OMAP24XX_DMA_MCBSP2_TX
  119. #define AUDIO_DMA_RX OMAP24XX_DMA_MCBSP2_RX
  120. #endif
  121. #define OMAP_MCBSP_READ(base, reg) __raw_readw((base) + OMAP_MCBSP_REG_##reg)
  122. #define OMAP_MCBSP_WRITE(base, reg, val) __raw_writew((val), (base) + OMAP_MCBSP_REG_##reg)
  123. /************************** McBSP SPCR1 bit definitions ***********************/
  124. #define RRST 0x0001
  125. #define RRDY 0x0002
  126. #define RFULL 0x0004
  127. #define RSYNC_ERR 0x0008
  128. #define RINTM(value) ((value)<<4) /* bits 4:5 */
  129. #define ABIS 0x0040
  130. #define DXENA 0x0080
  131. #define CLKSTP(value) ((value)<<11) /* bits 11:12 */
  132. #define RJUST(value) ((value)<<13) /* bits 13:14 */
  133. #define DLB 0x8000
  134. /************************** McBSP SPCR2 bit definitions ***********************/
  135. #define XRST 0x0001
  136. #define XRDY 0x0002
  137. #define XEMPTY 0x0004
  138. #define XSYNC_ERR 0x0008
  139. #define XINTM(value) ((value)<<4) /* bits 4:5 */
  140. #define GRST 0x0040
  141. #define FRST 0x0080
  142. #define SOFT 0x0100
  143. #define FREE 0x0200
  144. /************************** McBSP PCR bit definitions *************************/
  145. #define CLKRP 0x0001
  146. #define CLKXP 0x0002
  147. #define FSRP 0x0004
  148. #define FSXP 0x0008
  149. #define DR_STAT 0x0010
  150. #define DX_STAT 0x0020
  151. #define CLKS_STAT 0x0040
  152. #define SCLKME 0x0080
  153. #define CLKRM 0x0100
  154. #define CLKXM 0x0200
  155. #define FSRM 0x0400
  156. #define FSXM 0x0800
  157. #define RIOEN 0x1000
  158. #define XIOEN 0x2000
  159. #define IDLE_EN 0x4000
  160. /************************** McBSP RCR1 bit definitions ************************/
  161. #define RWDLEN1(value) ((value)<<5) /* Bits 5:7 */
  162. #define RFRLEN1(value) ((value)<<8) /* Bits 8:14 */
  163. /************************** McBSP XCR1 bit definitions ************************/
  164. #define XWDLEN1(value) ((value)<<5) /* Bits 5:7 */
  165. #define XFRLEN1(value) ((value)<<8) /* Bits 8:14 */
  166. /*************************** McBSP RCR2 bit definitions ***********************/
  167. #define RDATDLY(value) (value) /* Bits 0:1 */
  168. #define RFIG 0x0004
  169. #define RCOMPAND(value) ((value)<<3) /* Bits 3:4 */
  170. #define RWDLEN2(value) ((value)<<5) /* Bits 5:7 */
  171. #define RFRLEN2(value) ((value)<<8) /* Bits 8:14 */
  172. #define RPHASE 0x8000
  173. /*************************** McBSP XCR2 bit definitions ***********************/
  174. #define XDATDLY(value) (value) /* Bits 0:1 */
  175. #define XFIG 0x0004
  176. #define XCOMPAND(value) ((value)<<3) /* Bits 3:4 */
  177. #define XWDLEN2(value) ((value)<<5) /* Bits 5:7 */
  178. #define XFRLEN2(value) ((value)<<8) /* Bits 8:14 */
  179. #define XPHASE 0x8000
  180. /************************* McBSP SRGR1 bit definitions ************************/
  181. #define CLKGDV(value) (value) /* Bits 0:7 */
  182. #define FWID(value) ((value)<<8) /* Bits 8:15 */
  183. /************************* McBSP SRGR2 bit definitions ************************/
  184. #define FPER(value) (value) /* Bits 0:11 */
  185. #define FSGM 0x1000
  186. #define CLKSM 0x2000
  187. #define CLKSP 0x4000
  188. #define GSYNC 0x8000
  189. /************************* McBSP MCR1 bit definitions *************************/
  190. #define RMCM 0x0001
  191. #define RCBLK(value) ((value)<<2) /* Bits 2:4 */
  192. #define RPABLK(value) ((value)<<5) /* Bits 5:6 */
  193. #define RPBBLK(value) ((value)<<7) /* Bits 7:8 */
  194. /************************* McBSP MCR2 bit definitions *************************/
  195. #define XMCM(value) (value) /* Bits 0:1 */
  196. #define XCBLK(value) ((value)<<2) /* Bits 2:4 */
  197. #define XPABLK(value) ((value)<<5) /* Bits 5:6 */
  198. #define XPBBLK(value) ((value)<<7) /* Bits 7:8 */
  199. /* we don't do multichannel for now */
  200. struct omap_mcbsp_reg_cfg {
  201. u16 spcr2;
  202. u16 spcr1;
  203. u16 rcr2;
  204. u16 rcr1;
  205. u16 xcr2;
  206. u16 xcr1;
  207. u16 srgr2;
  208. u16 srgr1;
  209. u16 mcr2;
  210. u16 mcr1;
  211. u16 pcr0;
  212. u16 rcerc;
  213. u16 rcerd;
  214. u16 xcerc;
  215. u16 xcerd;
  216. u16 rcere;
  217. u16 rcerf;
  218. u16 xcere;
  219. u16 xcerf;
  220. u16 rcerg;
  221. u16 rcerh;
  222. u16 xcerg;
  223. u16 xcerh;
  224. };
  225. typedef enum {
  226. OMAP_MCBSP1 = 0,
  227. OMAP_MCBSP2,
  228. OMAP_MCBSP3,
  229. } omap_mcbsp_id;
  230. typedef int __bitwise omap_mcbsp_io_type_t;
  231. #define OMAP_MCBSP_IRQ_IO ((__force omap_mcbsp_io_type_t) 1)
  232. #define OMAP_MCBSP_POLL_IO ((__force omap_mcbsp_io_type_t) 2)
  233. typedef enum {
  234. OMAP_MCBSP_WORD_8 = 0,
  235. OMAP_MCBSP_WORD_12,
  236. OMAP_MCBSP_WORD_16,
  237. OMAP_MCBSP_WORD_20,
  238. OMAP_MCBSP_WORD_24,
  239. OMAP_MCBSP_WORD_32,
  240. } omap_mcbsp_word_length;
  241. typedef enum {
  242. OMAP_MCBSP_CLK_RISING = 0,
  243. OMAP_MCBSP_CLK_FALLING,
  244. } omap_mcbsp_clk_polarity;
  245. typedef enum {
  246. OMAP_MCBSP_FS_ACTIVE_HIGH = 0,
  247. OMAP_MCBSP_FS_ACTIVE_LOW,
  248. } omap_mcbsp_fs_polarity;
  249. typedef enum {
  250. OMAP_MCBSP_CLK_STP_MODE_NO_DELAY = 0,
  251. OMAP_MCBSP_CLK_STP_MODE_DELAY,
  252. } omap_mcbsp_clk_stp_mode;
  253. /******* SPI specific mode **********/
  254. typedef enum {
  255. OMAP_MCBSP_SPI_MASTER = 0,
  256. OMAP_MCBSP_SPI_SLAVE,
  257. } omap_mcbsp_spi_mode;
  258. struct omap_mcbsp_spi_cfg {
  259. omap_mcbsp_spi_mode spi_mode;
  260. omap_mcbsp_clk_polarity rx_clock_polarity;
  261. omap_mcbsp_clk_polarity tx_clock_polarity;
  262. omap_mcbsp_fs_polarity fsx_polarity;
  263. u8 clk_div;
  264. omap_mcbsp_clk_stp_mode clk_stp_mode;
  265. omap_mcbsp_word_length word_length;
  266. };
  267. /* Platform specific configuration */
  268. struct omap_mcbsp_ops {
  269. void (*request)(unsigned int);
  270. void (*free)(unsigned int);
  271. int (*check)(unsigned int);
  272. };
  273. struct omap_mcbsp_platform_data {
  274. unsigned long phys_base;
  275. u32 virt_base;
  276. u8 dma_rx_sync, dma_tx_sync;
  277. u16 rx_irq, tx_irq;
  278. struct omap_mcbsp_ops *ops;
  279. char const *clk_name;
  280. };
  281. struct omap_mcbsp {
  282. struct device *dev;
  283. unsigned long phys_base;
  284. u32 io_base;
  285. u8 id;
  286. u8 free;
  287. omap_mcbsp_word_length rx_word_length;
  288. omap_mcbsp_word_length tx_word_length;
  289. omap_mcbsp_io_type_t io_type; /* IRQ or poll */
  290. /* IRQ based TX/RX */
  291. int rx_irq;
  292. int tx_irq;
  293. /* DMA stuff */
  294. u8 dma_rx_sync;
  295. short dma_rx_lch;
  296. u8 dma_tx_sync;
  297. short dma_tx_lch;
  298. /* Completion queues */
  299. struct completion tx_irq_completion;
  300. struct completion rx_irq_completion;
  301. struct completion tx_dma_completion;
  302. struct completion rx_dma_completion;
  303. /* Protect the field .free, while checking if the mcbsp is in use */
  304. spinlock_t lock;
  305. struct omap_mcbsp_platform_data *pdata;
  306. struct clk *clk;
  307. };
  308. int omap_mcbsp_init(void);
  309. void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
  310. int size);
  311. void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg * config);
  312. int omap_mcbsp_request(unsigned int id);
  313. void omap_mcbsp_free(unsigned int id);
  314. void omap_mcbsp_start(unsigned int id);
  315. void omap_mcbsp_stop(unsigned int id);
  316. void omap_mcbsp_xmit_word(unsigned int id, u32 word);
  317. u32 omap_mcbsp_recv_word(unsigned int id);
  318. int omap_mcbsp_xmit_buffer(unsigned int id, dma_addr_t buffer, unsigned int length);
  319. int omap_mcbsp_recv_buffer(unsigned int id, dma_addr_t buffer, unsigned int length);
  320. int omap_mcbsp_spi_master_xmit_word_poll(unsigned int id, u32 word);
  321. int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 * word);
  322. /* SPI specific API */
  323. void omap_mcbsp_set_spi_mode(unsigned int id, const struct omap_mcbsp_spi_cfg * spi_cfg);
  324. /* Polled read/write functions */
  325. int omap_mcbsp_pollread(unsigned int id, u16 * buf);
  326. int omap_mcbsp_pollwrite(unsigned int id, u16 buf);
  327. #endif